package com.hkts.naturalgasauthentication.base.dao;

import com.hkts.naturalgasauthentication.base.entity.HontUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.Transient;
import java.util.Date;
import java.util.List;

public interface HontUserDao extends JpaRepository<HontUser,Integer> {
   @Query("from HontUser  where userName=:username OR mobile=:username")
   HontUser findHontUserByUserNameOrMobile(String username);

   @Query("from HontUser  where userName=:username")
   HontUser findByUserName(String username);
   HontUser findByMobile(String mobile);
   @Query("from HontUser  where mobile=:mobile")
   List<HontUser> customFind(String mobile);

   @Override
   <S extends HontUser> S save(S s);
   @Query("update HontUser set password=:password")
   HontUser updatePassword(String password);
   @Query("update HontUser set nickName=:nickname")
   HontUser updateNickname(String nickname);
   @Query("update HontUser set mobile=:mobile where id=:id")
   HontUser updateMobile(String mobile,String id);
   @Transient
   @Modifying//增删改必须有这个注解
   @Query(value = "update hont_user set update_time=:updateTime where id=:id",nativeQuery = true)
   void updateLastTimeById(Date updateTime,String id);

   @Transient
   @Modifying//增删改必须有这个注解
   @Query(value = "update hont_user set open_id=:openid where id=:id",nativeQuery = true)
   void updateopenId(String openid,String id);

   HontUser findById(String id);

   @Transient
   @Modifying//增删改必须有这个注解
   @Query(value = "update hont_user set mobile =:mobile  where id = :id",nativeQuery = true)
   void updateMobileById(String mobile,String id);

   HontUser findByOpenId(String openid);
}
